#include "userprovider.h"
#include <QDebug>
#include "txtuserreader.h"
#include "dbuserreader.h"
#include "txtuserwriter.h"
#include "dbuserwriter.h"

UserProvider::UserProvider()
{
    Source src = GameSettings::Instance()->userInfoSource();
    if(src == testSource)
    {
        reader = new EmptyUserReader("");
        writer = new EmptyUserWriter("");
    }
    if(src == TxtSource)
    {
        reader = new txtuserreader("users.txt");
        writer = new TxtUserWriter("users.txt");
    }
    if(src == DBSource)
    {
        reader = new dbuserreader("db_name.sqlite");
        writer = new DBUserWriter("db_name.sqlite");
    }
    this->users = reader->readUsers();
}

QList<User*> *UserProvider::getUsers()
{
    return this->users;
}

void UserProvider::saveUsers(QList<User *> *users)
{
    writer->writeUsers(users);
}
